package Thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

public class Demo45 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 10; i++) {
            int id = i;
            executorService.submit(()->{
                System.out.println("Thread " + id + " is running");
                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                System.out.println("Thread " + id + " is exiting");
                countDownLatch.countDown();
            });

        }
        countDownLatch.await();
        System.out.println("Thread "  +" is exiting");
        executorService.shutdown();
    }
}
